package com.ware4u.fx.news.server.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@EnableSwagger2
public class SwaggerConfig {
	
	@Value("${server.port}")
	private String port;
	
	@Bean
	public GroupedOpenApi news() {
		String[] paths = { "/api/news/**" };
		return GroupedOpenApi.builder().group("新闻接口")
									.pathsToMatch(paths)   
									.build();
	}


	@Bean
	public GroupedOpenApi catalog() {
		String[] paths = { "/api/catalog/**" };
		return GroupedOpenApi.builder().group("板块接口")
				.pathsToMatch(paths)
				.build();
	}

	@Bean
	public OpenAPI customOpenAPI() {  //@Value("${springdoc.version}") String appVersion
		String securitySchemeName = "bearerAuth";
		return new OpenAPI()
				.info(new Info().title("奉贤新闻API").version("1.0.0").description("POWER BY WARE4U")
						.contact(new Contact().email("sendreams@hotmail.com").name("陈洪"))
						.termsOfService("http://swagger.io/terms/")
						.license(new License().name("Apache 2.0").url("http://springdoc.org")))
				.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
				.components(new Components().addSecuritySchemes(securitySchemeName,
						new SecurityScheme()
								.type(SecurityScheme.Type.HTTP)
								.scheme("bearer")
								.bearerFormat("JWT")));
	}
}
